//
//  SEDoctorApplyController.m
//  kuaiyi
//
//  Created by Alphts on 16/7/5.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SEDoctorApplyController.h"
#import "DoctorCell.h"
#import "SEDoctorModel.h"
#import "SEDoctorParticularsVC.h"

@interface SEDoctorApplyController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView * tableView;

//存放数据
@property(nonatomic,strong)NSArray * dataArray;



@end

@implementation SEDoctorApplyController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setUpTableView];
    
    
}

- (void)setUpTableView{
    
    [self.view addSubview:self.tableView];
    

}

#pragma mark -- 代理方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
    SEDoctorParticularsVC * VC = [[SEDoctorParticularsVC alloc]init];
    
    VC.title = @"预约医生信息详情";
    VC.indexPath = indexPath.row;
    
    VC.model = self.dataArray[indexPath.row];
        
    
    [self.navigationController pushViewController:VC animated:YES];
    
    
//    deselect 取消选中;
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 90;
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    DoctorCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell == nil) {
        
        cell = [[DoctorCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        
    }
    
    cell.doctroModel = self.dataArray[indexPath.row];
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
}

#pragma mark -- lazy
- (UITableView *)tableView{
    
    if (_tableView == nil) {
        
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        _tableView.dataSource = self;
   
    }
    return _tableView;
    
    
}

- (NSArray *)dataArray{
    
    if (_dataArray == nil) {
        
        
        NSString * path = [[NSBundle mainBundle]pathForResource:@"Doctor.plist" ofType:nil];
        
        NSArray * temp = [NSArray arrayWithContentsOfFile:path];
        
        NSMutableArray * mutable = [NSMutableArray array];
        
        [temp enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
           
            
            SEDoctorModel * model = [SEDoctorModel doctorModelWithDict:obj];
            
            [mutable addObject:model];
            
            
            
        }];
        
        _dataArray = mutable;
        
    }
    
    return _dataArray;
}




@end
